 $.validator.setDefaults({
    highlight:function(e){
        $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
    },
    success:function(e){e.closest(".form-group").removeClass("has-error").addClass("has-success")},errorElement:"span",
    errorPlacement:function(e,r){
        e.appendTo(r.is(":radio")||r.is(":checkbox")?r.parent().parent().parent():r.parent())
    },
    errorClass:"help-block m-b-none",
    validClass:"help-block m-b-none"
}),
$().ready(function(){
    //$("#commentForm").validate();
    var e="<i class='fa fa-times-circle'></i> ";
    $("#myForm").validate({
        rules:{
                option:"required",
                flag:'required',
                lastname:"required",
                oldpwd:{required:!0,remote:'ajax.php?action=isOldPwd'},
                password:{required:!0,minlength:5},
                //confirm_password:{required:!0,minlength:5,equalTo:"#password"},
                //email:{required:!0,email:!0},
                topic:{required:"#newsletter:checked",minlength:2},
                agree:"required"
            },
        messages:{
                username:{required:e+"请输入用户名",remote:'请修正用户名'},
                option:e+"选择权限组",
                flag:e+"选择flag",
                lastname:e+"请输入您的名字",
                oldpwd:{required:e+"请输入您的原密码",
                remote:e+"请修正原密码"},
                password:{required:e+"请输入您的密码",
                minlength:e+"密码必须5个字符以上"},
                confirm_password:{required:e+"请再次输入密码",minlength:e+"密码必须5个字符以上",equalTo:e+"两次输入的密码不一致"},
                email:e+"请输入您的E-mail",
                agree:{required:e+"必须同意协议后才能注册",element:"#agree-error"
            }
        }
    });
    // $("#username").focus(function(){
    //     var e=$("#firstname").val(),
    //         r=$("#lastname").val();
    //     e&&r&&!this.value&&(this.value=e+"."+r)
    // })
});